package model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Player {
	private String name;

	private GameBoard gameBoard;

	private Jar jar;

	private List<House> houses = new ArrayList<House>();

	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}

	public Jar getJar() {
		return jar;
	}

	public void setJar(Jar jar) {
		if (this.jar != jar) {
			Jar old = this.jar;
			this.jar = jar;
			if (old != null) {
				old.setPlayer(null);
			}
			if (jar != null) {
				jar.setPlayer(this);
			}
		}
	}

	public GameBoard getGameBoard() {
		return gameBoard;
	}

	public void setGameBoard(GameBoard gameBoard) {
		this.gameBoard = gameBoard;
	}

	public List<House> getHouses() {
		return Collections.unmodifiableList(houses);
	}

	public void addHouse(House house) {
		house.setPlayer(this);
		if (!houses.contains(house)) {
			houses.add(house);
		}
	}

	public void removeHouse(House house) {
		house.setPlayer(null);
		houses.remove(house);
	}

}
